import { useTable, LIST_TYPE } from '@crud/index';
import { getCashList } from '@/api/crm-agency/dyj/cash';
import { formatParamsSelectVal } from '@/utils';

// 查询
export const statusOptions = [
  { label: '不限', value: -1 },
  { label: '待审核', value: 0 },
  { label: '已打款', value: 1 },
  { label: '申请驳回', value: 2 }
];

// 表格
export const useTableList = (options: any = {}) => {
  const columns: any = [
    { label: '代理账号名', prop: 'colnel_name', minWidth: 160, fixed: 'left' },
    { label: '代理手机号', prop: 'colonel_mobile', minWidth: 160 },
    { label: '打款信息', prop: 'remittance', render: 'remittance', minWidth: 160 },
    { label: '申请时间', prop: 'add_time', type: 'dateTime', minWidth: 177 },
    { label: '申请结算金额', prop: 'total_fee', minWidth: 160, render: (s:any) => s.row.total_fee ? '￥'+s.row.total_fee : '--' }, // TODO: 接口返回元 需要处理
    { label: '打款金额', prop: 'remittance_fee', minWidth: 160, render: (s:any) => s.row.status === 1 ? s.row.remittance_fee : '--' },
    { label: '操作', align: 'center', width: 160, render: 'actions', fixed: 'right' }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.AGENCY,
    params: {
      key_word: '',
      status: -1,
      from_dt: undefined,
      to_dt: undefined
    },
    columns: columns,
    getParams: ({ _timeArr = [], ...params }) => {
      // 处理时间参数
      if (_timeArr?.length) {
        const [begin, end] = _timeArr;
        params.from_dt = begin;
        params.to_dt = end;
      }
      return {
        ...params,
        ...formatParamsSelectVal(
          [
            ['commission_status', -1],
            ['pay_type', -1],
            ['product', -1],
            ['team_count', -1],
            ['user_type', -1]
          ],
          params
        )
      };
    },
    getList: getCashList
  });
};
